package com.chenyaowei.web.controller.member;

import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.core.page.TableDataInfo;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.common.utils.SecurityUtils;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.member.domain.CywMemberStatisticsInfo;
import com.chenyaowei.member.service.ICywMemberStatisticsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员统计信息Controller
 * 
 * @author 陈耀威
 * @date 2023-11-30
 */
@RestController
@RequestMapping("/member/memberStatisticsInfo")
public class CywMemberStatisticsInfoController extends BaseController
{
    @Autowired
    private ICywMemberStatisticsInfoService cywMemberStatisticsInfoService;

    @GetMapping("/currentUser")
    public AjaxResult getInfoByMemberId()
    {
        return success(cywMemberStatisticsInfoService.selectInfoByMemberId(SecurityUtils.getUserId()));
    }

    /**
     * 查询会员统计信息列表
     */
//    @PreAuthorize("@ss.hasPermi('member:memberStatisticsInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywMemberStatisticsInfo cywMemberStatisticsInfo)
    {
        startPage();
        List<CywMemberStatisticsInfo> list = cywMemberStatisticsInfoService.selectCywMemberStatisticsInfoList(cywMemberStatisticsInfo);
        return getDataTable(list);
    }

    /**
     * 导出会员统计信息列表
     */
    @PreAuthorize("@ss.hasPermi('member:memberStatisticsInfo:export')")
    @Log(title = "会员统计信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywMemberStatisticsInfo cywMemberStatisticsInfo)
    {
        List<CywMemberStatisticsInfo> list = cywMemberStatisticsInfoService.selectCywMemberStatisticsInfoList(cywMemberStatisticsInfo);
        ExcelUtil<CywMemberStatisticsInfo> util = new ExcelUtil<CywMemberStatisticsInfo>(CywMemberStatisticsInfo.class);
        util.exportExcel(response, list, "会员统计信息数据");
    }

    /**
     * 获取会员统计信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('member:memberStatisticsInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywMemberStatisticsInfoService.selectCywMemberStatisticsInfoById(id));
    }

    /**
     * 新增会员统计信息
     */
    @PreAuthorize("@ss.hasPermi('member:memberStatisticsInfo:add')")
    @Log(title = "会员统计信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywMemberStatisticsInfo cywMemberStatisticsInfo)
    {
        return toAjax(cywMemberStatisticsInfoService.insertCywMemberStatisticsInfo(cywMemberStatisticsInfo));
    }

    /**
     * 修改会员统计信息
     */
//    @PreAuthorize("@ss.hasPermi('member:memberStatisticsInfo:edit')")
    @Log(title = "会员统计信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywMemberStatisticsInfo cywMemberStatisticsInfo)
    {
        return toAjax(cywMemberStatisticsInfoService.updateCywMemberStatisticsInfo(cywMemberStatisticsInfo));
    }

    /**
     * 删除会员统计信息
     */
//    @PreAuthorize("@ss.hasPermi('member:memberStatisticsInfo:remove')")
    @Log(title = "会员统计信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywMemberStatisticsInfoService.deleteCywMemberStatisticsInfoByIds(ids));
    }
}
